import 'package:flutter/material.dart';

class ComposeView1500Text extends StatefulWidget {
  const ComposeView1500Text({super.key});

  @override
  State<ComposeView1500Text> createState() => _ComposeView1500TextState();
}

class _ComposeView1500TextState extends State<ComposeView1500Text> {
  final DateTime _start = DateTime.now(); // 页面启动时间
  int buildCount = 0; // 实际 build 次数

  @override
  void initState() {
    super.initState();

    // 页面渲染完成后回调
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final duration =
          DateTime.now().difference(_start).inMilliseconds;
      debugPrint("🕒 页面构建 + 渲染耗时：$duration ms");
      debugPrint("🧮 实际 build 了 $buildCount 个 item");
    });
  }

  Widget _buildItem(int index) {
    buildCount++; // 每次构建就计数
    final bg = index.isEven ? const Color(0xFFF5F5F5) : Colors.white;
    return Container(
      width: 300,
      height: 50,
      margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        // border: Border.all(color: Colors.grey, width: 1),
        color: bg, // ✅ 行背景色
        border: Border.all(color: Colors.grey, width: 1),
      ),
      alignment: Alignment.centerLeft,
      child: Text(
        'Item #$index',
        style: const TextStyle(fontSize: 16),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('ComposeView1500Text')),
      body: ListView(
        children: List.generate(1500, _buildItem),
      ),
    );
  }
}
